﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using com.cgWorkstudio.BIMP.Library.Properties;

namespace com.cgWorkstudio.BIMP.Library.uc {
    public enum IndexTextButtonType {
        RunButton,
        SettingButton
    }
    public partial class UC_IndexTextButton:UserControl {
        IndexTextButtonType _ButtonType = IndexTextButtonType.RunButton;
        [Description("按钮类型")]
        public IndexTextButtonType ButtonType {
            get {
                return _ButtonType;
            }
            set {
                _ButtonType = value;
                setButtonDefaultPic();
            }
        }
        public UC_IndexTextButton() {
            InitializeComponent();
            this.MouseMove += new MouseEventHandler(UC_IndexTextButton_MouseMove);
            this.MouseLeave += new EventHandler(UC_IndexTextButton_MouseLeave);
            this.MouseUp += new MouseEventHandler(UC_IndexTextButton_MouseUp);
            this.MouseDown += new MouseEventHandler(UC_IndexTextButton_MouseDown);
        }

        void UC_IndexTextButton_MouseDown(object sender,MouseEventArgs e) {
            mouseMoving = true;
            setButtonDownPic();
        }

        void setButtonDefaultPic() {
            switch(ButtonType) {
                case IndexTextButtonType.RunButton:
                    this.BackgroundImage = Resources.IndexButton_Run_Default;
                    break;
                case IndexTextButtonType.SettingButton:
                    this.BackgroundImage = Resources.IndexButton_Setting_Default;
                    break;
            }
        }
        void setButtonHoverPic() {
            switch(ButtonType) {
                case IndexTextButtonType.RunButton:
                    this.BackgroundImage = Resources.IndexButton_Run_Hover;
                    break;
                case IndexTextButtonType.SettingButton:
                    this.BackgroundImage = Resources.IndexButton_Setting_Hover;
                    break;
            }
        }
        void setButtonDownPic() {
            switch(ButtonType) {
                case IndexTextButtonType.RunButton:
                    this.BackgroundImage = Resources.IndexButton_Run_Down;
                    break;
                case IndexTextButtonType.SettingButton:
                    this.BackgroundImage = Resources.IndexButton_Setting_Down;
                    break;
            }
        }
        bool mouseMoving = false;
        void UC_IndexTextButton_MouseLeave(object sender,EventArgs e) {
            mouseMoving = false;
            setButtonDefaultPic();
        }

        void UC_IndexTextButton_MouseMove(object sender,MouseEventArgs e) {
            if(mouseMoving == true) {
                return;
            }
            mouseMoving = true;
            setButtonHoverPic();

        }
        void UC_IndexTextButton_MouseUp(object sender,MouseEventArgs e) {
            mouseMoving = true;
            setButtonDefaultPic();
        }
    }
}
